<?php
header ("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<menu>\n";

include("../../tools/mysql.php");
db_connect();

$sqlstr = "SELECT menu_id, m_level, name, name_zh, up_id, linkto FROM menu WHERE deleted=0 ORDER BY menu_id ASC";
$re = db_query($sqlstr);

// 标签是否封闭
$is_closed = array();

// 数据条数
$num = count($re);

for ($i = 0; $i < $num; $i ++)
{
	$level = $re[$i]["m_level"];
	$next_level = $re[$i + 1]["m_level"];
	$next_level = ($next_level != NULL) ? $next_level : 1;
	$linkto = $re[$i]["linkto"];
	$linkto = ($linkto != NULL) ? $linkto : "linkto";
	echo "<level" . $level . " id=\"" . $re[$i]["menu_id"] . "\" name=\"" . $re[$i]["name"] . "\" namezh=\"" . $re[$i]["name_zh"] . "\" linkto=\"" . $linkto . "\">\n";
	// 处理结束标签
	if ($level >= $next_level)
	{
		for ($j = $level; $j >= $next_level; $j --)
		{
			echo "</level" . $j . ">\n";
		}
	}
}
echo "</menu>\n";
?>
